/*
* $Id: AddInspectOperation.cpp 161 2010-10-03 23:45:28Z volok-aleksej@yandex.ru $
*
* Copyright 2009 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "AddInspectOperation.h"
#include "FieldValuesOperation.h"
#include "../Tables/JournalTable.h"
#include "../Tables/InspectTable.h"

CAddInspectOperation::CAddInspectOperation(){}
CAddInspectOperation::~CAddInspectOperation(){}

CAddInspectOperation::content::content(){
	Clear();
}
void CAddInspectOperation::content::Clear(){
	s_nId = 0;
	s_nIdFamily = 0;
	s_date = 0;
	s_nFrame = 0;
	s_nStrength = 0;
	s_nWax = 0;
	s_beeQueenStatus = Journal::DEFAULT;
	s_nAmbrosia = 0;
	s_nPumpHoney = 0;
	s_nFeeding = 0;
	s_disease = Journal::HEALTHY;
	s_strNote.clear();
	s_nIdRecord = 0;
	s_aUserFields.clear();
	s_aInspects.clear();
}

void CAddInspectOperation::AddValue(IDatabase* pDatabase){
	CFieldValuesOperation fvOper;
	fvOper.m_content.s_aUserFields = m_content.s_aUserFields;
	fvOper.m_content.s_table = TypeField::INSPECT;
	fvOper.AddValue(pDatabase);
	CJournalTable journal;
	journal.m_content.s_nIdFamily = m_content.s_nIdFamily;
	journal.m_content.s_date = m_content.s_date;
	journal.m_content.s_nFrame = m_content.s_nFrame;
	journal.m_content.s_nStrength = m_content.s_nStrength;
	journal.m_content.s_QueenBee = m_content.s_beeQueenStatus;
	journal.m_content.s_nWax = m_content.s_nWax;
	journal.m_content.s_nAmbrosia = m_content.s_nAmbrosia;
	journal.m_content.s_nEvacuation = m_content.s_nPumpHoney;
	journal.m_content.s_nFeeding = m_content.s_nFeeding;
	journal.m_content.s_disease = m_content.s_disease;
	journal.m_content.s_strNote = m_content.s_strNote;
	journal.m_content.s_nIdRecord = fvOper.m_content.s_nId;
	journal.SetValue(pDatabase);
	m_content.s_nId = journal.m_content.s_nId;
	m_content.s_nIdRecord = fvOper.m_content.s_nId;
	CInspectTable Inspect;
	for(std::vector<inspect>::iterator it = m_content.s_aInspects.begin(); it != m_content.s_aInspects.end(); it++){
		Inspect.m_content.s_nIdJournal = m_content.s_nId;
		Inspect.m_content.s_nIdHousing = it->s_nIdHousing;
		Inspect.m_content.s_strNameHousing = it->s_strNameHousing;
		Inspect.m_content.s_nBrood = it->s_nBrood;
		Inspect.m_content.s_nHoney = it->s_nHoney;
		Inspect.m_content.s_nOpenBrood = it->s_nOpenBrood;
		Inspect.m_content.s_nCloseBrood = it->s_nCloseBrood;
		Inspect.m_content.s_nGoodsHoney = it->s_nGoodsHoney;
		Inspect.SetValue(pDatabase);
	}
}